package natappvip.liujinliang;

import natappvip.liujinliang.client.ConnectionHandler;
import natappvip.liujinliang.common.ResponseCode;

/**
 * @ClassName:  FileSystemClient   
 * @Despt: 文件系统客户端 
 * @Auth: Liujinliang 
 * @Date: 2018年7月24日 下午10:46:18
 */
public class FileSystemClient {
	
	public static final String SAVE_LOCAL_URL = "http://localhost:8090/upload";
	
	public static final String METADATA_LOCAL_URL = "http://localhost:8090/mdata?uuid=";
	
	public static final String DOWNLOAD_LOCAL_URL = "http://localhost:8090/download?uuid=";
	
	public static final String DEL_LOCAL_URL = "http://localhost:8090/delete?uuid=";
	
	public static void main(String[] args) {
		
		upload(new String[] {"Test.txt"});
//		delete("8bb01093-af50-42db-b2a3-aaed273a53cb");
//		getMetadata("8bb01093-af50-42db-b2a3-aaed273a53cb");
//		download("8bb01093-af50-42db-b2a3-aaed273a53cb", "download");
	}
	
	/**
	 * @Title: delete   
	 * @Despt: 删除文件  
	 * @param:       
	 * @return: void      
	 * @throws
	 */
	public static void delete(String uuid) {
		String res = ConnectionHandler.delete(DEL_LOCAL_URL, uuid);
		
		// 打印到控制台
		System.out.println(res);
	}
	
	/**
	 * @Title: download   
	 * @Despt: 下载文件   
	 * @param: @param uuid
	 * @param: @param fileName      
	 * @return: void      
	 * @throws
	 */
	public static void download(String uuid, String fileName) {
		
		int res = ConnectionHandler.download(DOWNLOAD_LOCAL_URL, uuid, fileName);
		
		// 打印到控制台
		System.out.println((res == ResponseCode.SUCCESS.getCode()) ? "下载成功" : "下载失败");
	}
	
	/**
	 * @Title: getMetadata   
	 * @Despt: 获取文件的存储信息  
	 * @param:       
	 * @return: void      
	 * @throws
	 */
	public static void getMetadata(String uuid) {
		
		String res = ConnectionHandler.mdata(METADATA_LOCAL_URL, uuid);
		
		// 打印到控制台
		System.out.println(res);
	}
	
	/**
	 * @Title: upload   
	 * @Despt: 上传文件
	 * @param: @param filePath      
	 * @return: void      
	 * @throws
	 */
	public static void upload(String[] filePath) {
		
		String msg = ConnectionHandler.upload(SAVE_LOCAL_URL, null, filePath);
		
		// 打印到控制台
		System.out.println(msg);
	}

}
